﻿using System.ComponentModel;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System;

namespace MyFloridaHouse.libSvOpenDistricts.Dialogs
{
    public class PrefCustomizeCriteriaDlg : _BaseDlg
    {
        private PrefCustomizeCriteriaDlgView dlgWindow = new PrefCustomizeCriteriaDlgView();

        public PrefCustomizeCriteriaDlg(PropertyChangedEventHandler propertyChangedEventHandler, StackPanel childWindowStackPanel )
        {
            InitializeDlgWindow(propertyChangedEventHandler, childWindowStackPanel, dlgWindow);
        }

        public void Reset(List<string> criteriaDatasetNameList, string gridCriteriaDatasetName, string labelCriteriaDatasetName, string fillCriteriaDatasetName)
        {
            if (criteriaDatasetNameList.Count == 0) throw new Exception("PrefCustomizeCriteriaDlg: No criteria dataset are in the criteriaDatasetName List - cannot continue.");
            this.criteriaDatasetNameList = new ObservableCollection<string>(criteriaDatasetNameList);
            this.gridCriteriaDatasetNameListSelectedIndex = criteriaDatasetNameList.IndexOf(gridCriteriaDatasetName);
            this.labelCriteriaDatasetNameListSelectedIndex = criteriaDatasetNameList.IndexOf(labelCriteriaDatasetName);
            this.fillCriteriaDatasetNameListSelectedIndex = criteriaDatasetNameList.IndexOf(fillCriteriaDatasetName);
        }

        #region form data properties

        private ObservableCollection<string> _criteriaDatasetNameList = new ObservableCollection<string>();
        public ObservableCollection<string> criteriaDatasetNameList
        {
            get 
            { 
                return _criteriaDatasetNameList; 
            }
            set
            {
                if (_criteriaDatasetNameList != value)
                {
                    _criteriaDatasetNameList = value;
                    NotifyPropertyChanged("criteriaDatasetNameList");
                }
            }
        }

        private int _gridCriteriaDatasetNameListSelectedIndex = -1;
        public int gridCriteriaDatasetNameListSelectedIndex
        {
            get { return _gridCriteriaDatasetNameListSelectedIndex; }
            set
            {
                if (_gridCriteriaDatasetNameListSelectedIndex != value)
                {
                    _gridCriteriaDatasetNameListSelectedIndex = value;
                    NotifyPropertyChanged("gridCriteriaDatasetNameListSelectedIndex");
                }
            }
        }

        private int _labelCriteriaDatasetNameListSelectedIndex = -1;
        public int labelCriteriaDatasetNameListSelectedIndex
        {
            get { return _labelCriteriaDatasetNameListSelectedIndex; }
            set
            {
                if (_labelCriteriaDatasetNameListSelectedIndex != value)
                {
                    _labelCriteriaDatasetNameListSelectedIndex = value;
                    NotifyPropertyChanged("labelCriteriaDatasetNameListSelectedIndex");
                }
            }
        }

        private int _fillCriteriaDatasetNameListSelectedIndex = -1;
        public int fillCriteriaDatasetNameListSelectedIndex
        {
            get { return _fillCriteriaDatasetNameListSelectedIndex; }
            set
            {
                if (_fillCriteriaDatasetNameListSelectedIndex != value)
                {
                    _fillCriteriaDatasetNameListSelectedIndex = value;
                    NotifyPropertyChanged("fillCriteriaDatasetNameListSelectedIndex");
                }
            }
        }

        public string gridCriteriaDatasetName 
        { 
            get 
            {
                int index = ((gridCriteriaDatasetNameListSelectedIndex >= 0) & (gridCriteriaDatasetNameListSelectedIndex < criteriaDatasetNameList.Count)) ? gridCriteriaDatasetNameListSelectedIndex : 0;
                return criteriaDatasetNameList[index]; 
            } 
        }
        public string labelCriteriaDatasetName
        {
            get
            {
                int index = ((labelCriteriaDatasetNameListSelectedIndex >= 0) & (labelCriteriaDatasetNameListSelectedIndex < criteriaDatasetNameList.Count)) ? labelCriteriaDatasetNameListSelectedIndex : 0;
                return criteriaDatasetNameList[index];
            }
        }
        public string fillCriteriaDatasetName
        {
            get
            {
                int index = ((fillCriteriaDatasetNameListSelectedIndex >= 0) & (fillCriteriaDatasetNameListSelectedIndex < criteriaDatasetNameList.Count)) ? fillCriteriaDatasetNameListSelectedIndex : 0;
                return criteriaDatasetNameList[index];
            }
        }

        #endregion

    }
}
